import java.util.*;

/**
 * @author LKQ
 * @date 2022/4/10 16:06
 * @description 动态规划 dp[i] 从 [0..i]需要的最少操作次数
 * 可知 当 A[i] >= A[i+1]时，那么 A[i]增加时，A[i+1]可以顺便加一，那么A[i+1]不占用操作次数
 * 当A[i] < A[i+1]时，那么A[i]+1时，A[i+1]也顺便加1，A[i+1]还是需要 A[i+1] - A[i]次操作次数
 */
public class Solution3 {
    public static void main(String[] args) {
        Solution3 solution = new Solution3();
        int[] target = {1, 2, 3, 2, 1};
        solution.minNumberOperations(target);
    }
    public int minNumberOperations(int[] target) {
        int n = target.length;
        int[] dp = new int[n];
        dp[0] = target[0];
        for (int i = 1; i < n; i++) {
            if (target[i] <= target[i-1]) {
                dp[i] = dp[i-1];
            }else {
                dp[i] = dp[i-1] + target[i] - target[i-1];
            }
        }
        return dp[n-1];
    }
}
